<template>
	<view class="content">
		<view class="position-group">
			<threeChoose :mulunum="mulunum" :fatherToInfo='fatherToInfo'></threeChoose>

		</view>

	</view>

</template>

<script>
	import threeChoose from '@/components/three-choose/three-choose.vue';

	export default {
		data() {
			return {
				id: '', // 课程id
				mulunum: [], //课程资源数组
				// courseChapterList: [],
				courseVideosList: [],
				fatherToInfo: {
					defaultIcon: '../../static/icon/right.png', //展开后图标
					currentIcon: '../../static/icon/0123.png', //恢复后图标
					shoufenq: true, //一级下拉是否需要手风琴效果
					twoshoufenq: true, //二级下拉是否需要手风琴效果
					thirdrightcolor: '#666', //第三项字体颜色
					thirdrightchoosed: 'red' //右侧被选中后的颜色变化
				},
				id: '',
				courseId: ''
			}
		},
		async onLoad(option) { //取出父页面传来的参数
			this.id = option.id
			await this.getCourseDetail(this.id) //调用方法

		},
		methods: {
			async getCourseDetail(id) {
				let res = await this.$myRequest({
					url: '/api/mobile/schoolcoursesection/all',
					data: {
						courseId: id
					}
				})
				if (res.code == 200) {
					this.mulunum = res.data
					this.mulunum.forEach((value, index) => {
						if (value.open === undefined) {
							value.courseChapterList = []
							value.open = false // 加字段且赋值
							//id,courId,传引索 防止子章节数据一样,防止覆盖数据
							this.getChapterViceList(this.mulunum[index].id, this.mulunum[index].courseId,
								index)
						}
					})

				}

			},
			// 获取子章节
			async getChapterViceList(id, courseId, ind) {
				let res = await this.$myRequest({
					url: '/api/mobile/schoolcoursesection/all',
					data: {
						courseId: courseId,
						parentId: id
					},
				})
				if (res.success) {
					// console.log(res.data);
					res.data.forEach((value, index) => { // index 是数组下标
						this.mulunum[ind].courseChapterList = res.data // 赋值给引索下的courseChapterList 
						this.mulunum[ind].courseChapterList[index]
							.courseVideosList = []; //添加数组courseVideosList
						this.mulunum[ind].courseChapterList[index].secondOpen =
							false // 在courseVideosList里添加secondOpen字段
						this.getCourseVideosList(ind, index, res.data[index].id) //调用方法
					})
				}
				// console.log(this.mulunum);
			},
			// 获取资源
			async getCourseVideosList(ind, index, parentId) { // 传mulunum下标 和courseChapterList下标 和id
				let res = await this.$myRequest({
					url: '/api/mobile/schoolcourseresource/getResourceBySection/' + parentId,
					Date: {
						parentId: parentId
					}
				})
				if (res.success) {
					res.data.forEach((value, indexed) => { //
						this.mulunum[ind].courseChapterList[index].courseVideosList = res
							.data // 赋值给courseVideosList
						this.mulunum[ind].courseChapterList[index].courseVideosList[indexed].thirdOpen =
							false // 添加字段thirdOpen
					})
				}
				// console.log("数据>");
				// console.log(this.mulunum);
			},
			toCourseSpace() {
				uni.navigateTo({
					url: '../courseSpace/courseSpace'
				})
			}
		},
		components: {
			threeChoose
		},
	}
</script>

<style lang="scss" scoped>

</style>
